package fr.umlv.ig.extraWindows;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import fr.umlv.ig.model.MetroModelImpl;
import fr.umlv.ig.xml.MetroModelFactory;


/**
 * Windows to configure the party.
 */
@SuppressWarnings("serial")
public class TrainConfigurationWindow extends ExtraWindow {
	
	/**
	 * MinesweeperModelImp to configure
	 */
	private final MetroModelImpl model;

	
	/**
	 * Initialize a windows to configure and {@link MinesweeperModelImp} and start
	 * a new party.
	 * @param owner owner's window.
	 * @param title title of the ExtraWindow.
	 * @param model model which will be configure.
	 */
	public TrainConfigurationWindow(JFrame owner, String title,MetroModelImpl model) {
		super(owner, title, true, 400, 300);
		this.model = model;
		init();
		dispose();
	}

	/**
	 * Initializes the component in the windows.
	 */
	private void init() {
		JPanel p = new JPanel(new GridLayout(1, 2));
	
		final JPanel personalConfigurationPanel = new JPanel();
		
		GridBagConstraints gbc = new GridBagConstraints();
		personalConfigurationPanel.setLayout(new GridBagLayout());
		personalConfigurationPanel.setBorder(BorderFactory.createTitledBorder("Configuration des trains"));

		gbc.gridwidth=3;
		gbc.weightx=1f;
		gbc.weighty=100f;
		JLabel rowsLabel = new JLabel("Ligne 1");
		personalConfigurationPanel.add(rowsLabel,gbc);
		
		
		final SpinnerNumberModel spinnerRowsModel = new SpinnerNumberModel(1, 1, 30, 1);
		final JSpinner columnSpinner = new JSpinner(spinnerRowsModel);
		columnSpinner.setPreferredSize(new Dimension(40,20));
		gbc.gridwidth=3;
		gbc.gridwidth=GridBagConstraints.REMAINDER;
		personalConfigurationPanel.add(columnSpinner,gbc);
		

		gbc.gridwidth=3;
		JLabel colsLabel = new JLabel("Ligne 2");
		personalConfigurationPanel.add(colsLabel,gbc);
		
		final SpinnerNumberModel spinnerColsModel = new SpinnerNumberModel(1, 1, 30, 1);
		final JSpinner rowsSpinner = new JSpinner(spinnerColsModel);
		rowsSpinner.setPreferredSize(new Dimension(40,20));
		gbc.gridwidth=GridBagConstraints.REMAINDER;
		personalConfigurationPanel.add(rowsSpinner,gbc);
		
		gbc.gridwidth=3;
		JLabel minesLabel = new JLabel("Ligne 3");
		personalConfigurationPanel.add(minesLabel,gbc);
		
		
		final SpinnerNumberModel spinnerBombsModel = new SpinnerNumberModel(1, 1,30, 1);
		
		final JSpinner minesSpinner = new JSpinner(spinnerBombsModel);		
		 minesSpinner .setPreferredSize(new Dimension(40,20));
		gbc.gridwidth=GridBagConstraints.REMAINDER;
		personalConfigurationPanel.add( minesSpinner ,gbc);
		
		p.add(personalConfigurationPanel);
		add(p);
		/*********************************************************/
		

		JPanel downPanel = new JPanel();
		JButton buttonOk = new JButton("OK");
		
		downPanel.add(buttonOk);
		
		JButton buttonCancel = new JButton("annuler");
		downPanel.add(buttonCancel);
		add(downPanel,BorderLayout.SOUTH);
	}
	
	@Override
	public void start() {
		setLocationRelativeTo(getOwner());
		setVisible(true);
	}
	
	public static void main(String[] args) {
//		JFrame frame = new JFrame();
//		frame.setSize(600,600);
//		frame.setMinimumSize(new Dimension(400, 400));
//		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		
//		JPanel panel = new JPanel(new BorderLayout());
//		
//		
//		MetroModelFactory metroFactory = null;
//		try {
//			metroFactory = MetroModelFactory.newInstance();
//		} catch (ParserConfigurationException e) {
//			System.err.println(e.getMessage());
//			return;
//		} catch (SAXException e) {
//			System.err.println(e.getMessage());
//			return;
//		} catch (IOException e) {
//			System.err.println(e.getMessage());
//			return;
//		}
//
//		BufferedImage imageMap = new BufferedImage(900, 650, BufferedImage.TYPE_3BYTE_BGR);
//		MetroModelImpl model = metroFactory.getMetroModelImpl();
//		
//		TrainConfigurationWindow window = new GameOptionWindow(frame, "window", model);
//		panel.add(window);
//		frame.getContentPane().add(panel);
//		
//		frame.pack();
//		frame.setVisible(true);
	}
	
}


